package com.hntxk.cqzd.flup.service.impl;


import com.hntxk.core.framework.service.impl.BaseServiceImpl;
import com.hntxk.cqzd.basicinfo.basepatient.entity.BasePatient;
import com.hntxk.cqzd.common.service.CommonFileService;
import com.hntxk.cqzd.flup.entity.FlupFile;
import com.hntxk.cqzd.flup.entity.FlupInfo;
import com.hntxk.cqzd.flup.service.FlupFileService;
import com.hntxk.sp.log.model.ActionLog;
import com.hntxk.sp.log.model.ActionType;
import com.hntxk.sp.util.LogRecordUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @author <a href="huangbiquan@hotmail.com">Huang.Biquan</a>
 * @Description: 基本信息管理接口实现类 <br>
 * @Project: SP <br>
 * @date 2019/6/3 10:01 <br>
 */
@Service("flupFileManageService")
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class FlupFileServiceImpl extends BaseServiceImpl<FlupFile> implements FlupFileService {


    public static String FLUPFILE_MAPPER_NAMESPACE = "com.hntxk.cqzd.flup.mapper.FlupFileMapper.";

    @Autowired
    @Qualifier("commonFileServiceImpl")
    private CommonFileService commonFileService;

    public FlupFileServiceImpl() {
        super(FLUPFILE_MAPPER_NAMESPACE);
    }

    @Override
    public List<FlupFile> getByFkId(Long id) {
        FlupFile flupFile=new FlupFile();
        flupFile.setFlupId(id);
        List<FlupFile> query = (List<FlupFile>) query(FLUPFILE_MAPPER_NAMESPACE + "getByFkId", flupFile);
        return query;
    }

    @Override
    public List<FlupFile> getByDiacrisisId(Long diacrisisId) {
        FlupFile flupFile=new FlupFile();
        flupFile.setDiacrisisId(diacrisisId);
        List<FlupFile> query = (List<FlupFile>) query(FLUPFILE_MAPPER_NAMESPACE + "getByDiacrisisId", flupFile);
        return query;
    }

    @Override
    public ResponseEntity<byte[]> getFile(String fileCode) {
        FlupFile flupFile = get(FLUPFILE_MAPPER_NAMESPACE + "getByFlieCode", fileCode);
        flupFile.setFileDownloadNo(flupFile.getFileDownloadNo()+1);
        update(FLUPFILE_MAPPER_NAMESPACE+"update",flupFile);
        String filePath=flupFile.getFileAddress();
        String fileName = flupFile.getFileName();
        return  commonFileService.getFile(filePath,fileName);
    }
}
